package com.dsteiner.widgets.client;

import java.beans.PropertyChangeListener;

import com.dsteiner.widgets.client.Widgets.IWidget;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.Widgets.SimplePanelExt;
import com.dsteiner.widgets.client.controller.RoundBorderController;
import com.dsteiner.widgets.client.resources.RoundBorderCssResource;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Widget;

public class RoundBorder extends LazyWidget{

	public static class RoundBorderModel {
		private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(
				this);

		public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
			propertyChangeSupport.registerPropertyChangeListener(propertyName, listener);
		}

		private String styleNames;

		public String getStyleNames() {
			return styleNames;
		}

		public void setStyleNames(String styleNames) {
			String oldStyleNames = this.styleNames;
			this.styleNames = styleNames;
			propertyChangeSupport.firePropertyChange("styleNames", oldStyleNames, styleNames);
		}
		
		private IWidget contentWidget;

		public IWidget getContentWidget() {
			return contentWidget;
		}

		public void setContentWidget(IWidget contentWidget) {
			IWidget oldContentWidget = this.contentWidget;
			this.contentWidget = contentWidget;
			propertyChangeSupport.firePropertyChange("contentWidget", oldContentWidget, contentWidget);
		}
		private RoundBorderCssResource cssResource;

		public RoundBorderCssResource getCssResource() {
			return cssResource;
		}

		public void setCssResource(RoundBorderCssResource cssResource) {
			RoundBorderCssResource oldCssResource = this.cssResource;
			this.cssResource = cssResource;
			propertyChangeSupport.firePropertyChange("cssResource", oldCssResource, cssResource);
		}
	}
	
	private final RoundBorderModel roundBorderModel;
	private RoundBorderController nineBoxController = new RoundBorderController();
	public RoundBorder(RoundBorderModel roundBorderModel) {
		this.roundBorderModel = roundBorderModel;
	}
	
	@Override
	public Widget createContentWidget() {
		DecoratorPanel decoratorPanel = new DecoratorPanel();
		SimplePanelExt contentPanelHolder = new SimplePanelExt();

		decoratorPanel.setWidget(contentPanelHolder);
		
		nineBoxController.registerRoundBorderModel(roundBorderModel);
		nineBoxController.registerRoundBorder(this);
		nineBoxController.registerContentPanelHolder(contentPanelHolder);

		return decoratorPanel;
	}

}
